pub mod lit;
pub mod seq;
pub mod fse;
pub mod byte;
pub mod frame;
pub mod block;
pub mod huffman;
pub mod workspace;

#[cfg(test)]
mod tests {
    use std::{io::{BufReader}, fs::File};

    use std::io::{Seek};

    use crate::workspace::OutputWorkSpace;

    use super::*;

    use frame::FrameResult;

    #[test]
    fn it_works() -> FrameResult<()> {
        let mut byte_reader = byte::ByteReader::new(BufReader::new(File::open("./Cargo.toml.zst").expect("not open")));
        let frame = frame::Frame::deserialize_from(&mut byte_reader)?;
        let mut origin_file = byte_reader.into_inner().into_inner();
        let read_position = origin_file.stream_position().expect("what");
        let file_size = origin_file.metadata().unwrap().len();
        assert_eq!(read_position, file_size);
        let mut output_file = std::fs::OpenOptions::new()
            .write(true)
            .create(true)
            .truncate(true)
            .open("./my_uncompressed_result.txt")
            .unwrap();
        let mut output_work_space = OutputWorkSpace::new();
        let decoded_size = frame.uncompressed_to(&mut output_file, &mut output_work_space).expect("something is wrong");
        println!("decode with {} bytes", decoded_size);
        Ok(())
    }
}
